package com.gu.controller;

import com.gu.service.EduVideoUploadService;
import entity.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * Description:
 *
 * @Autor: Rolin
 * datetime: 05-27-15:32
 */
@RestController
@Api(tags = "视频上传控件")
@CrossOrigin
@RequestMapping("/eduUpload")
public class EduVideoUploadController {

    @Resource
    private EduVideoUploadService eduVideoUploadService ;

    @ApiOperation("上传视频")
    @PostMapping("/uploadVideo")
    public CommonResult uploadVideo (MultipartFile file){
        String videoId = eduVideoUploadService.upload(file);
        return !StringUtils.isEmpty(videoId)?CommonResult.success().data("videoId",videoId):CommonResult.error().data("videoId",null);
    }

    @ApiOperation("删除课程视频")
    @DeleteMapping("/deleteVideo/{videoId}")
    public CommonResult deleteVideoByVideoId(@PathVariable("videoId")String videoId){
        eduVideoUploadService.deleteVideoByVideoId(videoId);
        return CommonResult.success();
    }

    @ApiOperation("获取播放凭证")
    @GetMapping("/getPlayAuth/{id}")
    public CommonResult getPlayAuth(@PathVariable("id")String videoId){
       String playAuth = eduVideoUploadService.getPlayAuth(videoId);
        return !StringUtils.isEmpty(playAuth)? CommonResult.success().data("playAuth",playAuth):CommonResult.error();
    }
}
